<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Templates extends OC_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('templates/template_model');
	}

	function _remap($method, $params = array())
	{
		parent::_remap($method, $params);
		
		if (method_exists($this, $method))
			return call_user_func_array(array($this, $method), $params);
		else
			show_404();
	}

	function init_header()
	{
		$this->header['jeasyui'] = TRUE;
		$this->header['source_bot'] = array(
			script_tag(site_url('templates/themescript/app/templates.js'))
		);
	}

	function index()
	{
		$this->init_header();
		$this->header['nav'] = 'contents';
		$this->header['pagetitle'] = 'Pages';
		$this->view('templates/template_view');
	}

	function load_data()
	{
		$params = $this->input->post();
		$result = $this->template_model->get_all($params);
		print(json_encode($result));
	}

	function save_data()
	{
		$post = $this->input->post();
		
		unset($post['files']);

		if (empty($post['tpl_id']))
		{
			unset($post['tpl_id']);
			$this->template_model->add($post);
		}
		else
		{
			$this->template_model->edit($post, array('tpl_id' => $post['tpl_id']));
		}

		print(json_encode(array(
			'success' => TRUE
		)));
	}

	function delete_data()
	{
		$post = $this->input->post();
		$this->template_model->delete(array('tpl_id' => $post['tpl_id']));
		print(json_encode(array(
			'success' => TRUE
		)));
	}

}

/* End of file templates.php */
/* Location: .//D/noobsprojects/swanstwenty/dnetnorfintek/module_admin/templates/controllers/templates.php */